import { defineStore } from "pinia";

//defineStore两个参数:1模块名称 2对象包含state函数、getters和actions对象
export const useStore = defineStore('login', {
    persist: {
        enabled: true,
        strategies: [
            {
                // 缓存的模块名称
                key: 'login',
                // 保存位置，默认保存在sessionStorage
                storage: localStorage,
                // 缓存哪些状态
                paths: ["username", "token", "type","routes"]
            }
        ]
    },
    state() {
        return {
            username: '',
            token: '',
            routes: [],
            type: '',
            // isLogin:false,
        }
    },
    actions: {
        setRoutes(newRoutes) {
            this.routes = newRoutes;
        },
        setUsername(newName) {
            this.username = newName;
        },
        setToken(newToken) {
            this.token = newToken;
        },
        setType(netType) {
            this.type = netType;
        },
    },
    getters:{
        isLogin(state){
            return !!state.token
        }
    }

})